package com.qys.training.server.controller;

import com.itextpdf.text.DocumentException;
import com.qys.training.base.dto.BaseResult;
import com.qys.training.base.dto.PDFTextConfig;
import com.qys.training.biz.auth.service.ItextService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;

@RestController
@RequestMapping("/itext")
public class ItextController {
    @Resource
    private ItextService itextServiceImpl;

    @PostMapping("/addText")
    public BaseResult addText(Long id, PDFTextConfig config) {
        try {
            int i = itextServiceImpl.addText(id, config);
            if (i > 0) {
                return BaseResult.success("修改成功");
            }
        } catch (DocumentException | IOException e) {
            e.printStackTrace();
            return BaseResult.success("修改失败");
        }
        return BaseResult.success("修改失败");
    }

}
